package com.zjp;

import com.google.common.collect.*;
import org.junit.jupiter.api.Test;


//@SuppressWarnings(value = {"all", "rawtypes"})
public class
TkRangeTest {

    @SuppressWarnings(value = {"UnstableApiUsage"})
    public void tMap() {
        RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
        rangeMap.put(Range.closed(1, 10), "foo"); // {[1, 10] => "foo"}
        rangeMap.put(Range.open(3, 6), "bar"); // {[1, 3] => "foo", (3, 6) => "bar", [6, 10] => "foo"}
        rangeMap.put(Range.open(10, 20), "foo"); // {[1, 3] => "foo", (3, 6) => "bar", [6, 10] => "foo", (10, 20) => "foo"}
        rangeMap.remove(Range.closed(5, 11)); // {[1, 3] => "foo", (3, 5) => "bar", (11, 20) => "foo"}
    }


    @SuppressWarnings("UnstableApiUsage")
    public void tSet() {
        RangeSet<Integer> rangeSet = TreeRangeSet.create();
        //noinspection UnstableApiUsage
        rangeSet.add(Range.closed(1, 10)); // {[1, 10]}
        rangeSet.add(Range.closedOpen(11, 15)); // disconnected range: {[1, 10], [11, 15)}
        rangeSet.add(Range.closedOpen(15, 20)); // connected range; {[1, 10], [11, 20)}
        rangeSet.add(Range.openClosed(0, 0)); // empty range; {[1, 10], [11, 20)}
        rangeSet.remove(Range.open(5, 10)); // splits [1, 10]; {[1, 5], [10, 10], [11, 20)}


    }

    // closed X>= && <=Y
    // closedOpen X>= && <Y
    // openClosed X> && <=Y


    @Test
    public void t1Apple() {


        RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
        rangeMap.put(Range.closed(1, 5), "小苹果");
        rangeMap.put(Range.closed(6, 10), "中苹果");
        rangeMap.put(Range.closed(11, 15), "大苹果");
        System.out.println("这是一个" + rangeMap.get(9));
    }

}
